package com.zhijian.warehouse.manage.controller;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.vo.request.StoreSaveOrUpdateVo;
import com.zhijian.warehouse.manage.entity.vo.request.StoreSearchVo;
import com.zhijian.warehouse.manage.entity.vo.request.StoreWarehouseLocationSearchVo;
import com.zhijian.warehouse.manage.entity.vo.request.WarehouseLocationProductSearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.StoreVo;
import com.zhijian.warehouse.manage.entity.vo.response.StoreWarehouseLocationProjectVo;
import com.zhijian.warehouse.manage.entity.vo.response.StoreWarehouseLocationVo;
import com.zhijian.warehouse.manage.entity.vo.response.StoreWarehouseVo;
import com.zhijian.warehouse.manage.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 库存管理 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-27 13:42:54
 */
@Slf4j
@Controller
@Api(tags = "库存查询")
public class StoreController {

    @Autowired
    private StoreService service;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store")
    @ApiOperation("新增")
    public boolean insert(@RequestBody StoreSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/store/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/store/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody StoreSaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.modify(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/store/{id}")
    @ApiOperation("根据id查询")
    public StoreVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/page")
    @ApiOperation("分页查询")
    public Page<StoreVo> selectByCondition(@RequestBody(required = false) StoreSearchVo param) {
        if (param == null)
            param = StoreSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 包含了库位信息的库存数据
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/warehouse/location/page")
    @ApiOperation("包含了库位信息的库存数据")
    public Page<StoreWarehouseLocationProjectVo> selectStoreWarehouseLocationProject(@RequestBody(required = false) StoreWarehouseLocationSearchVo param) {
        if (param == null)
            param = StoreWarehouseLocationSearchVo.builder().build();
        log.info("{} - {}| selectStoreWarehouseLocationProject info", this.getClass().getSimpleName(), param);
        return service.selectStoreWarehouseLocationProject(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/list")
    @ApiOperation("列表查询")
    public List<StoreVo> selectList(@RequestBody(required = false) StoreSearchVo param) {
        if (param == null)
            param = StoreSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }

    /**
     * 根据仓库id 库位id 商品id 查询库存数量
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/product/count")
    @ApiOperation("根据仓库id 库位id 商品id 查询库存数量")
    public String selectProductCount(@RequestBody(required = false) StoreSearchVo param) {
        if (param == null)
            param = StoreSearchVo.builder().build();
        log.info("{} - {}| selectProduct info", this.getClass().getSimpleName(), param);
        return service.selectProduct(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/store/list/warehouse/location/product")
    @ApiOperation("根据仓库id和产品id查询库位及库存信息")
    public List<StoreWarehouseLocationVo> selectWarehouseLocationProductList(@RequestBody(required = false) WarehouseLocationProductSearchVo param) {
        if (param == null)
            param = WarehouseLocationProductSearchVo.builder().build();
        log.info("{} - {}| selectWarehouseLocationProductList info", this.getClass().getSimpleName(), param);
        return service.getStoreWarehouseLocations(param.getWarehouseId(),param.getProductId());
    }
}
